package org.example.view.Frame;

import org.example.view.componet.ATMButton;
import org.example.view.componet.BackgroundScene;
import org.example.view.componet.ButtonTypeEnum;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * 取款页面
 */
public class GetAtm extends JPanel {
    /**
     * 背景
     */
    private BackgroundScene backgroundScene;

    /**
     * 退出按钮
     */
    private ATMButton offButton;

    /**
     * 操作框
     */
    private JLabel pane;

    /**
     * 取款金额
     */
    private JLabel money;

    /**
     * 输入取款金额
     */
    private JTextField moneyInput;

    /**
     * 清除按钮
     */
    private ATMButton clearButton;

    /**
     * 确定按钮
     */
    private ATMButton sureButton;


    public GetAtm(JPanel panel) {
        this.addContent(panel);
    }

    private void addContent(JPanel panel) {
        this.setLayout(null);

        /**
         * 退出按钮（跳转选择页面）
         */
        this.offButton = new ATMButton(ButtonTypeEnum.退出, 450, 650);
        this.offButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CardLayout cardLayout = (CardLayout) panel.getLayout();
                cardLayout.show(panel, "choose");
            }
        });
        this.add(this.offButton);

        /**
         * 清除按钮（清除输入的余额）
         */
        this.clearButton = new ATMButton(ButtonTypeEnum.清除, 20, 475);
        this.clearButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                moneyInput.setText(null);
            }
        });
        this.add(this.clearButton);

        /**
         * 确认按钮（提交余额）
         */
        this.sureButton = new ATMButton(ButtonTypeEnum.确定, 880, 475);
        this.clearButton.addActionListener(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {

            }
        });
        this.add(this.sureButton);

        /**
         * 取款金额
         */
        this.money = new JLabel();
        this.money.setText("请输入取款金额");
        this.money.setFont(new Font("宋体", Font.ITALIC, 21));
        this.money.setForeground(Color.blue);
        this.money.setBounds(260, 330, 150, 25);
        this.add(this.money);

        /**
         * 输入取款金额
         */
        this.moneyInput = new JTextField();
        this.moneyInput.setBounds(425, 325, 200, 35);
        this.add(this.moneyInput);

        /**
         * 操作框
         */
        this.pane = new JLabel(new ImageIcon("/Users/cengyunke/Desktop/atm1/ATMGUI/src/main/java/org/example/img/pane.jpg"));
        this.pane.setBounds(210, 250, 620, 200);
        this.add(this.pane);

        /**
         * 背景
         */
        this.backgroundScene = new BackgroundScene();
        this.add(this.backgroundScene);
    }
}
